﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MC2Development.DevWebServer.Interfaces;
using MC2Development.DevWebServer;
using System.Configuration;

namespace DevWebServer.Test
{
    /// <summary>
    /// Custom web request authenticator that uses credentials held in 
    /// the application configuration file appSettings section.
    /// </summary>
    class ConfigAuthenticator : IAuthenticator
    {
        /// <summary>
        /// Authenticates the user against credentials stored in the application configuration file
        /// </summary>
        /// <param name="suppliedCredentials">Credentials to be authenticated supplied with the request</param>
        /// <param name="expectedCredentials">Not used</param>
        /// <returns>A boolean flag indicating if the credentials were authenticated</returns>
        public bool AuthenticateUser(Credentials suppliedCredentials, Credentials expectedCredentials)
        {
            bool blnAuthenticated = false;

            if (suppliedCredentials != null)
            {
                if (suppliedCredentials.Username == ConfigurationManager.AppSettings["Username"]
                        && suppliedCredentials.Password == ConfigurationManager.AppSettings["Password"])
                {
                    blnAuthenticated = true;
                }
            }

            return blnAuthenticated;
        }
    }
}
